package com.chenlonghai.sbmybatis.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


import com.chenlonghai.sbmybatis.entity.Contact;
import com.chenlonghai.sbmybatis.entity.ResultModel;
import com.chenlonghai.sbmybatis.service.ContactService;


@RestController
@RequestMapping("/contact")
public class ContactController {
	@Autowired
	private ContactService contactService;
	
	@RequestMapping(value="/list",method = RequestMethod.GET)
	public Map<String, Object> listContact(){
		Map<String, Object>modelMap = new HashMap<>();
		List<Contact>list = contactService.queryContact();
		modelMap.put("contactlist", list);
		return modelMap;
	}
	

	
	@RequestMapping(value="/add",method = { RequestMethod.POST, RequestMethod.GET })
	public Map<String, Object> addcontact(Contact contact){
	   Map<String, Object>modelMap = new HashMap<>();
	   contact.setCreateTime(new Date());
	   contact.setUpdateTime(new Date());
		boolean isOK= contactService.insertContact(contact);

	    ResultModel<Boolean>result = new ResultModel<Boolean>(isOK, modelMap);
        modelMap = result.getResltMap();
		return modelMap;
	}
	
}
